package com.tfleo.mealssenger.notification;

import com.tfleo.mealssenger.FoodActivity;
import com.tfleo.mealssenger.Main;
import com.tfleo.mealssenger.R;
import com.tfleo.mealssenger.R.drawable;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;

public class DemoNotification extends Service {
	NotificationManager mNotificationManager;
	Notification notification;
	SharedPreferences appSettings;
	
	public void onCreate() {
		super.onCreate();
		
		Context context = getApplicationContext();
		appSettings = getSharedPreferences(Main.USER_DATA, MODE_PRIVATE);
		
		String ns = Context.NOTIFICATION_SERVICE;
		mNotificationManager = (NotificationManager) getSystemService(ns);
		int notifIcon = R.drawable.icon;
		String ticker = "Testing";
		long when = System.currentTimeMillis();
		
		notification = new Notification(notifIcon, ticker, when);
		CharSequence contentTitle = "New notification";
		CharSequence contentText = "You've got mail!";
		Intent notificationIntent = new Intent(this, FoodActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
		
		notification.flags = Notification.FLAG_AUTO_CANCEL;
		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
		
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if(appSettings.getBoolean(Main.RECEIVE_NOTIF, true)) {
			mNotificationManager.notify(1, notification);
		}
		return START_STICKY;
	}
	
}
